package Jets.ui
{
   import flash.display.DisplayObjectContainer;
   import flash.events.Event;
   import flash.events.MouseEvent;
   
   import Jets.display.JSprite;
   import Jets.ui.skins.SkinStates;
   
   import game.managers.FilterManager;
   
   public class JCheckBox extends JStateButton
   {
	  public var canclick:Boolean = true;
	  protected var ms_nSelect:JSprite; 
	  
      public function JCheckBox(parent:DisplayObjectContainer=null, cx:Number=0, cy:Number=0, text:String="") 
	  {
         super(parent,cx,cy,text);
         this.setSize(16,16);
         this.addEventListener(MouseEvent.CLICK,this.onclick);
      }
      
      override protected function addChildren() : void 
	  {
         super.addChildren();
		 ms_nSelect = new JSprite(this);
      }
      
      protected function onclick(event:MouseEvent) : void 
	  {
         if(this.canclick)
         {
            selected = !selected;
            this.dispatchEvent(new Event(Event.CHANGE));
            invalidate();
         }
      }
      
	  override public function set skin(skinName:String):void
	  {
		  super.skin = skinName;
		  ms_nSelect.skin = skinName;
	  }
	  
	  override protected function onMouseUp(event:MouseEvent) : void 
	  {
		  if(this.sel)
		  {
			  ms_nSelect.state = SkinStates.SELECTED;
			  return;
		  }
		  super.onMouseUp(event);
	  }
	  
	  override public function set selected(value:Boolean) : void 
	  {
		  this.sel = value;
		  if(this.sel)
		  {
			  ms_nSelect.state = SkinStates.SELECTED;
		  }
		  else
		  {
			  ms_nSelect.state = SkinStates.UP;
		  }
	  }
	  
      override public function draw() : void 
	  {
         super.draw();
		 ms_nSelect.draw();
         this._label.x = this.height + 5;
		 ms_nSelect.x = (this.width - ms_nSelect.width)>>1;
		 ms_nSelect.y = (this.height - ms_nSelect.height)>>1;
      }
	  
   }
}
